package conf

import (
	"fmt"
	"github.com/spf13/viper"
)

type AppConf struct {
	MysqlConfig
	RedisConfig
}

type MysqlConfig struct {
	User     string
	Password string
	Host     string
	Port     int
	Database string
}
type RedisConfig struct {
	Addr     string
	Password string
	Db       int
}

var Conf AppConf

func Init() {
	viper.SetConfigFile("./conf/config.yaml")
	err := viper.ReadInConfig()
	if err != nil {
		fmt.Println("配置文件读取失败")
		return
	}
	err = viper.Unmarshal(&Conf)
	if err != nil {
		fmt.Println("配置文件解析失败")
		return
	}
	fmt.Println("配置文件读取成功")
}
